Use absolute path for CARGO_HOME
authorEduardo Bautista <me@eduardobautista.com>
Thu, 28 May 2015 20:18:45 +0000 (15:18 -0500)
committerEduardo Bautista <me@eduardobautista.com>
Thu, 28 May 2015 23:34:50 +0000 (18:34 -0500)
src/cargo/util/config.rs
tests/test_cargo_build_lib.rs

index 7681bc0cbffd7a3b8b56ca741b5f67e3d0422ce5..35924a7036594182702b6ad5a52ad439e0c1dac8 100644 (file)
@@ -39,7 +39,7 @@ impl Config {
         }));
 
         let mut cfg = Config {
-            home_path: try!(homedir().chain_error(|| {
+            home_path: try!(homedir(cwd.as_path()).chain_error(|| {
                 human("Cargo couldn't find your home directory. \
                       This probably means that $HOME was not set.")
             })),
@@ -423,8 +423,10 @@ impl ConfigValue {
     }
 }
 
-fn homedir() -> Option<PathBuf> {
-    let cargo_home = env::var_os("CARGO_HOME").map(PathBuf::from);
+fn homedir(cwd: &Path) -> Option<PathBuf> {
+    let cargo_home = env::var_os("CARGO_HOME").map(|home| {
+        cwd.join(home)
+    });
     let user_home = env::home_dir().map(|p| p.join(".cargo"));
     return cargo_home.or(user_home);
 }
@@ -450,7 +452,7 @@ fn walk_tree<F>(pwd: &Path, mut walk: F) -> CargoResult<()>
     // Once we're done, also be sure to walk the home directory even if it's not
     // in our history to be sure we pick up that standard location for
     // information.
-    let home = try!(homedir().chain_error(|| {
+    let home = try!(homedir(pwd).chain_error(|| {
         human("Cargo couldn't find your home directory. \
               This probably means that $HOME was not set.")
     }));
index 763fd0c1711b90eb5bcab3fddb3a56b98888e85a..476d2f14bdfce27c89439e61c70b3c5ede9556f7 100644 (file)
@@ -52,3 +52,33 @@ test!(build_with_no_lib {
                 execs().with_status(101)
                        .with_stderr("no library targets found"));
 });
+
+test!(build_with_relative_cargo_home_path {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+
+            name = "foo"
+            version = "0.0.1"
+            authors = ["wycats@example.com"]
+
+            [dependencies]
+
+            "test-dependency" = { path = "src/test_dependency" }
+        "#)
+        .file("src/main.rs", r#"
+            fn main() {}
+        "#)
+        .file("src/test_dependency/src/lib.rs", r#" "#)
+        .file("src/test_dependency/Cargo.toml", r#"
+            [package]
+
+            name = "test-dependency"
+            version = "0.0.1"
+            authors = ["wycats@example.com"]
+        "#);
+
+    assert_that(p.cargo_process("build").env("CARGO_HOME", "./cargo_home/"),
+                execs()
+                .with_status(0));
+});